from PIL import Image
import os
import sys
def getSpecifiedTypeFileFromDirectory(file_dir, suffixes):
    """
    获取路径下所有具某些指定后缀的文件
    :param file_dir: 根路径
    :param suffixes: 后缀集合
    :return:
    """
    L = []
    for dirpath, dirnames, filenames in os.walk(file_dir):
        for file in filenames:
            if file[0] == ".":
                continue
            if os.path.splitext(file)[1] in suffixes:
                currentPath = os.path.join(dirpath, file)
                L.append(currentPath)
    return L

def getFileNameNotSufFromPath(path):
    """
    从路径中获取文件名，不包含后缀
    :param path:
    :return:
    """
    basename = os.path.basename(path)
    return os.path.splitext(basename)[0]

def main(argv):
    originPath = argv[0]  # 原始路径
    targetPath = argv[1]  # 目标路径
    print("打开路径", originPath)
    print("存储路径", targetPath)

    jpegPath = getSpecifiedTypeFileFromDirectory(originPath,[".jpeg"])
    for path in jpegPath:
    	fileName = getFileNameNotSufFromPath(path)
    	imageJpeg = Image.open(path)
    	imageJpeg.save(targetPath+"/"+fileName+".jpg")


if __name__ == "__main__":
    main(sys.argv[1:])